//
//  DWHomeViewViewModel.swift
//  DWSwift
//
//  Created by GDL on 2025/6/23.
//

import Foundation

import Foundation
import Combine
import SwiftUI

class DWAdvertisingViewModel:ObservableObject{
    
    @Published var adList: [DWHomeAdModelItem] = []

    func fetchADList(){
        Task {
            do {
//                let result:DWBaseResponse<DWHomeAdModel> = try await DWNetworkManager.GET(path: "app-api/ad/list", params: ["shop_id":152])
               
                let result:DWBaseResponse<DWHomeAdModel> = try await DWNetworkManager.GET(path: DWHomeAPI.adAPI.rawValue, params: [:])
                if(result.isSuccess){
                    guard let ad:DWHomeAdModel=result.data else{
                        return
                    }
//                    let ad:DWHomeAdModel = result.data
                    // 主线程更新 UI
                    await MainActor.run { [weak self] in
                        guard let self = self else {
                           // print("self is deallocated, skip assignment")
                            return
                        }
                        self.adList = ad.list
                    }
                }else{

                }
            }catch {
                // 网络和json 解析错误码
            }
        }
    }
}
